/*
 * Copyright 2011 woozzu
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.com.darly.videoandroidpm.widget.indexlist;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;
import android.widget.TextView;

import cn.com.darly.videoandroidpm.R;

/**
 * 带标签的ListView
 * Copyright (c) 2017 Organization D.L. zhangyuhui All rights reserved.
 *
 * @author Darly/张宇辉/2018/5/7 11:24
 * @version 1.0/cn.com.darly.videoandroidpm.widget.indexlist
 */

public class IndexHideBar extends RelativeLayout implements IndexSliderBar.OnChooseLetterChangedListener {

    private TextView tv_hint;

    private IndexSliderBar.OnChooseLetterChangedListener onChooseLetterChangedListener;

    public IndexHideBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.item_view_slider, this);
        initView();
    }

    private void initView() {
        IndexSliderBar sideBar = (IndexSliderBar) findViewById(R.id.id_view_sideBar);
        tv_hint = (TextView) findViewById(R.id.id_view_hint);
        sideBar.setOnTouchingLetterChangedListener(this);
    }

    @Override
    public void onChooseLetter(String s) {
        tv_hint.setText(s);
        tv_hint.setVisibility(VISIBLE);
        if (onChooseLetterChangedListener != null) {
            onChooseLetterChangedListener.onChooseLetter(s);
        }
    }

    @Override
    public void onNoChooseLetter() {
        tv_hint.setVisibility(INVISIBLE);
        if (onChooseLetterChangedListener != null) {
            onChooseLetterChangedListener.onNoChooseLetter();
        }
    }

    public void setOnChooseLetterChangedListener(IndexSliderBar.OnChooseLetterChangedListener onChooseLetterChangedListener) {
        this.onChooseLetterChangedListener = onChooseLetterChangedListener;
    }
}